﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Jinhe.Storage
{
    public class MimeType
    {
        private static readonly string MimeTypeFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mimeTypes.txt");
        private static List<MimeType> mimeTypes;
        private static readonly object Lock = new object();
        private static bool isFirstRead = true;

        public string Ext { set; get; }

        public string Type { set; get; }

        public int Index { set; get; }

        public static MimeType GetMimeByExt(string ext)
        {
            if (mimeTypes == null || !mimeTypes.Any())
            {
                InitData();
            }
            ext = ext.ToLower();
            return mimeTypes.First(item => item.Ext == ext);
        }

        public static MimeType GetMimeByIndex(int index)
        {
            if (mimeTypes == null || !mimeTypes.Any())
            {
                InitData();
            }
            return mimeTypes.Count > index ? mimeTypes[index] : null;
        }

        #region 添加文件类型和内存初始化

        public static IEnumerable<MimeType> InitData()
        {
            if (mimeTypes == null)
            {
                mimeTypes = new List<MimeType>();
            }
            var list = new List<MimeType>()
            {
                new MimeType {Ext = ".3dm", Type = "x-world/x-3dmf"},
                new MimeType {Ext = ".3dmf", Type = "x-world/x-3dmf"},
                new MimeType {Ext = ".a", Type = "application/octet-stream"},
                new MimeType {Ext = ".aab", Type = "application/x-authorware-bin"},
                new MimeType {Ext = ".aam", Type = "application/x-authorware-map"},
                new MimeType {Ext = ".aas", Type = "application/x-authorware-seg"},
                new MimeType {Ext = ".abc", Type = "text/vnd.abc"},
                new MimeType {Ext = ".acgi", Type = "text/html"},
                new MimeType {Ext = ".afl", Type = "video/animaflex"},
                new MimeType {Ext = ".ai", Type = "application/postscript"},
                new MimeType {Ext = ".aif", Type = "audio/aiff"},
                new MimeType {Ext = ".aif", Type = "audio/x-aiff"},
                new MimeType {Ext = ".aifc", Type = "audio/aiff"},
                new MimeType {Ext = ".aifc", Type = "audio/x-aiff"},
                new MimeType {Ext = ".aiff", Type = "audio/aiff"},
                new MimeType {Ext = ".aiff", Type = "audio/x-aiff"},
                new MimeType {Ext = ".aim", Type = "application/x-aim"},
                new MimeType {Ext = ".aip", Type = "text/x-audiosoft-intra"},
                new MimeType {Ext = ".ani", Type = "application/x-navi-animation"},
                new MimeType {Ext = ".aos", Type = "application/x-nokia-9000-communicator-add-on-software"},
                new MimeType {Ext = ".aps", Type = "application/mime"},
                new MimeType {Ext = ".arc", Type = "application/octet-stream"},
                new MimeType {Ext = ".arj", Type = "application/arj"},
                new MimeType {Ext = ".arj", Type = "application/octet-stream"},
                new MimeType {Ext = ".art", Type = "image/x-jg"},
                new MimeType {Ext = ".asf", Type = "video/x-ms-asf"},
                new MimeType {Ext = ".asm", Type = "text/x-asm"},
                new MimeType {Ext = ".asp", Type = "text/asp"},
                new MimeType {Ext = ".asx", Type = "application/x-mplayer2"},
                new MimeType {Ext = ".asx", Type = "video/x-ms-asf"},
                new MimeType {Ext = ".asx", Type = "video/x-ms-asf-plugin"},
                new MimeType {Ext = ".au", Type = "audio/basic"},
                new MimeType {Ext = ".au", Type = "audio/x-au"},
                new MimeType {Ext = ".avi", Type = "application/x-troff-msvideo"},
                new MimeType {Ext = ".avi", Type = "video/avi"},
                new MimeType {Ext = ".avi", Type = "video/msvideo"},
                new MimeType {Ext = ".avi", Type = "video/x-msvideo"},
                new MimeType {Ext = ".avs", Type = "video/avs-video"},
                new MimeType {Ext = ".bcpio", Type = "application/x-bcpio"},
                new MimeType {Ext = ".bin", Type = "application/mac-binary"},
                new MimeType {Ext = ".bin", Type = "application/macbinary"},
                new MimeType {Ext = ".bin", Type = "application/octet-stream"},
                new MimeType {Ext = ".bin", Type = "application/x-binary"},
                new MimeType {Ext = ".bin", Type = "application/x-macbinary"},
                new MimeType {Ext = ".bm", Type = "image/bmp"},
                new MimeType {Ext = ".bmp", Type = "image/bmp"},
                new MimeType {Ext = ".bmp", Type = "image/x-windows-bmp"},
                new MimeType {Ext = ".boo", Type = "application/book"},
                new MimeType {Ext = ".book", Type = "application/book"},
                new MimeType {Ext = ".boz", Type = "application/x-bzip2"},
                new MimeType {Ext = ".bsh", Type = "application/x-bsh"},
                new MimeType {Ext = ".bz", Type = "application/x-bzip"},
                new MimeType {Ext = ".bz2", Type = "application/x-bzip2"},
                new MimeType {Ext = ".c", Type = "text/plain"},
                new MimeType {Ext = ".c", Type = "text/x-c"},
                new MimeType {Ext = ".c++", Type = "text/plain"},
                new MimeType {Ext = ".cat", Type = "application/vnd.ms-pki.seccat"},
                new MimeType {Ext = ".cc", Type = "text/plain"},
                new MimeType {Ext = ".cc", Type = "text/x-c"},
                new MimeType {Ext = ".ccad", Type = "application/clariscad"},
                new MimeType {Ext = ".cco", Type = "application/x-cocoa"},
                new MimeType {Ext = ".cdf", Type = "application/cdf"},
                new MimeType {Ext = ".cdf", Type = "application/x-cdf"},
                new MimeType {Ext = ".cdf", Type = "application/x-netcdf"},
                new MimeType {Ext = ".cer", Type = "application/pkix-cert"},
                new MimeType {Ext = ".cer", Type = "application/x-x509-ca-cert"},
                new MimeType {Ext = ".cha", Type = "application/x-chat"},
                new MimeType {Ext = ".chat", Type = "application/x-chat"},
                new MimeType {Ext = ".class", Type = "application/java"},
                new MimeType {Ext = ".class", Type = "application/java-byte-code"},
                new MimeType {Ext = ".class", Type = "application/x-java-class"},
                new MimeType {Ext = ".com", Type = "application/octet-stream"},
                new MimeType {Ext = ".com", Type = "text/plain"},
                new MimeType {Ext = ".conf", Type = "text/plain"},
                new MimeType {Ext = ".cpio", Type = "application/x-cpio"},
                new MimeType {Ext = ".cpp", Type = "text/x-c"},
                new MimeType {Ext = ".cpt", Type = "application/mac-compactpro"},
                new MimeType {Ext = ".cpt", Type = "application/x-compactpro"},
                new MimeType {Ext = ".cpt", Type = "application/x-cpt"},
                new MimeType {Ext = ".crl", Type = "application/pkcs-crl"},
                new MimeType {Ext = ".crl", Type = "application/pkix-crl"},
                new MimeType {Ext = ".crt", Type = "application/pkix-cert"},
                new MimeType {Ext = ".crt", Type = "application/x-x509-ca-cert"},
                new MimeType {Ext = ".crt", Type = "application/x-x509-user-cert"},
                new MimeType {Ext = ".csh", Type = "application/x-csh"},
                new MimeType {Ext = ".csh", Type = "text/x-script.csh"},
                new MimeType {Ext = ".css", Type = "application/x-pointplus"},
                new MimeType {Ext = ".css", Type = "text/css"},
                new MimeType {Ext = ".cxx", Type = "text/plain"},
                new MimeType {Ext = ".dcr", Type = "application/x-director"},
                new MimeType {Ext = ".deepv", Type = "application/x-deepv"},
                new MimeType {Ext = ".def", Type = "text/plain"},
                new MimeType {Ext = ".der", Type = "application/x-x509-ca-cert"},
                new MimeType {Ext = ".dif", Type = "video/x-dv"},
                new MimeType {Ext = ".dir", Type = "application/x-director"},
                new MimeType {Ext = ".dl", Type = "video/dl"},
                new MimeType {Ext = ".dl", Type = "video/x-dl"},
                new MimeType {Ext = ".doc", Type = "application/msword"},
                new MimeType {Ext = ".docx", Type = "application/msword"},
                new MimeType {Ext = ".dot", Type = "application/msword"},
                new MimeType {Ext = ".dp", Type = "application/commonground"},
                new MimeType {Ext = ".drw", Type = "application/drafting"},
                new MimeType {Ext = ".dump", Type = "application/octet-stream"},
                new MimeType {Ext = ".dv", Type = "video/x-dv"},
                new MimeType {Ext = ".dvi", Type = "application/x-dvi"},
                new MimeType {Ext = ".dwf", Type = "drawing/x-dwf (old)"},
                new MimeType {Ext = ".dwf", Type = "model/vnd.dwf"},
                new MimeType {Ext = ".dwg", Type = "application/acad"},
                new MimeType {Ext = ".dwg", Type = "image/vnd.dwg"},
                new MimeType {Ext = ".dwg", Type = "image/x-dwg"},
                new MimeType {Ext = ".dxf", Type = "application/dxf"},
                new MimeType {Ext = ".dxf", Type = "image/vnd.dwg"},
                new MimeType {Ext = ".dxf", Type = "image/x-dwg"},
                new MimeType {Ext = ".dxr", Type = "application/x-director"},
                new MimeType {Ext = ".el", Type = "text/x-script.elisp"},
                new MimeType {Ext = ".elc", Type = "application/x-bytecode.elisp (compiled elisp)"},
                new MimeType {Ext = ".elc", Type = "application/x-elc"},
                new MimeType {Ext = ".env", Type = "application/x-envoy"},
                new MimeType {Ext = ".eps", Type = "application/postscript"},
                new MimeType {Ext = ".es", Type = "application/x-esrehber"},
                new MimeType {Ext = ".etx", Type = "text/x-setext"},
                new MimeType {Ext = ".evy", Type = "application/envoy"},
                new MimeType {Ext = ".evy", Type = "application/x-envoy"},
                new MimeType {Ext = ".exe", Type = "application/octet-stream"},
                new MimeType {Ext = ".f", Type = "text/plain"},
                new MimeType {Ext = ".f", Type = "text/x-fortran"},
                new MimeType {Ext = ".f77", Type = "text/x-fortran"},
                new MimeType {Ext = ".f90", Type = "text/plain"},
                new MimeType {Ext = ".f90", Type = "text/x-fortran"},
                new MimeType {Ext = ".fdf", Type = "application/vnd.fdf"},
                new MimeType {Ext = ".fif", Type = "application/fractals"},
                new MimeType {Ext = ".fif", Type = "image/fif"},
                new MimeType {Ext = ".fli", Type = "video/fli"},
                new MimeType {Ext = ".fli", Type = "video/x-fli"},
                new MimeType {Ext = ".flo", Type = "image/florian"},
                new MimeType {Ext = ".flx", Type = "text/vnd.fmi.flexstor"},
                new MimeType {Ext = ".fmf", Type = "video/x-atomic3d-feature"},
                new MimeType {Ext = ".for", Type = "text/plain"},
                new MimeType {Ext = ".for", Type = "text/x-fortran"},
                new MimeType {Ext = ".fpx", Type = "image/vnd.fpx"},
                new MimeType {Ext = ".fpx", Type = "image/vnd.net-fpx"},
                new MimeType {Ext = ".frl", Type = "application/freeloader"},
                new MimeType {Ext = ".funk", Type = "audio/make"},
                new MimeType {Ext = ".g", Type = "text/plain"},
                new MimeType {Ext = ".g3", Type = "image/g3fax"},
                new MimeType {Ext = ".gif", Type = "image/gif"},
                new MimeType {Ext = ".gl", Type = "video/gl"},
                new MimeType {Ext = ".gl", Type = "video/x-gl"},
                new MimeType {Ext = ".gsd", Type = "audio/x-gsm"},
                new MimeType {Ext = ".gsm", Type = "audio/x-gsm"},
                new MimeType {Ext = ".gsp", Type = "application/x-gsp"},
                new MimeType {Ext = ".gss", Type = "application/x-gss"},
                new MimeType {Ext = ".gtar", Type = "application/x-gtar"},
                new MimeType {Ext = ".gz", Type = "application/x-compressed"},
                new MimeType {Ext = ".gz", Type = "application/x-gzip"},
                new MimeType {Ext = ".gzip", Type = "application/x-gzip"},
                new MimeType {Ext = ".gzip", Type = "multipart/x-gzip"},
                new MimeType {Ext = ".h", Type = "text/plain"},
                new MimeType {Ext = ".h", Type = "text/x-h"},
                new MimeType {Ext = ".hdf", Type = "application/x-hdf"},
                new MimeType {Ext = ".help", Type = "application/x-helpfile"},
                new MimeType {Ext = ".hgl", Type = "application/vnd.hp-hpgl"},
                new MimeType {Ext = ".hh", Type = "text/plain"},
                new MimeType {Ext = ".hh", Type = "text/x-h"},
                new MimeType {Ext = ".hlb", Type = "text/x-script"},
                new MimeType {Ext = ".hlp", Type = "application/hlp"},
                new MimeType {Ext = ".hlp", Type = "application/x-helpfile"},
                new MimeType {Ext = ".hlp", Type = "application/x-winhelp"},
                new MimeType {Ext = ".hpg", Type = "application/vnd.hp-hpgl"},
                new MimeType {Ext = ".hpgl", Type = "application/vnd.hp-hpgl"},
                new MimeType {Ext = ".hqx", Type = "application/binhex"},
                new MimeType {Ext = ".hqx", Type = "application/binhex4"},
                new MimeType {Ext = ".hqx", Type = "application/mac-binhex"},
                new MimeType {Ext = ".hqx", Type = "application/mac-binhex40"},
                new MimeType {Ext = ".hqx", Type = "application/x-binhex40"},
                new MimeType {Ext = ".hqx", Type = "application/x-mac-binhex40"},
                new MimeType {Ext = ".hta", Type = "application/hta"},
                new MimeType {Ext = ".htc", Type = "text/x-component"},
                new MimeType {Ext = ".htm", Type = "text/html"},
                new MimeType {Ext = ".html", Type = "text/html"},
                new MimeType {Ext = ".htmls", Type = "text/html"},
                new MimeType {Ext = ".htt", Type = "text/webviewhtml"},
                new MimeType {Ext = ".htx", Type = "text/html"},
                new MimeType {Ext = ".ice", Type = "x-conference/x-cooltalk"},
                new MimeType {Ext = ".ico", Type = "image/x-icon"},
                new MimeType {Ext = ".idc", Type = "text/plain"},
                new MimeType {Ext = ".ief", Type = "image/ief"},
                new MimeType {Ext = ".iefs", Type = "image/ief"},
                new MimeType {Ext = ".iges", Type = "application/iges"},
                new MimeType {Ext = ".iges", Type = "model/iges"},
                new MimeType {Ext = ".igs", Type = "application/iges"},
                new MimeType {Ext = ".igs", Type = "model/iges"},
                new MimeType {Ext = ".ima", Type = "application/x-ima"},
                new MimeType {Ext = ".imap", Type = "application/x-httpd-imap"},
                new MimeType {Ext = ".inf", Type = "application/inf"},
                new MimeType {Ext = ".ins", Type = "application/x-internett-signup"},
                new MimeType {Ext = ".ip", Type = "application/x-ip2"},
                new MimeType {Ext = ".isu", Type = "video/x-isvideo"},
                new MimeType {Ext = ".it", Type = "audio/it"},
                new MimeType {Ext = ".iv", Type = "application/x-inventor"},
                new MimeType {Ext = ".ivr", Type = "i-world/i-vrml"},
                new MimeType {Ext = ".ivy", Type = "application/x-livescreen"},
                new MimeType {Ext = ".jam", Type = "audio/x-jam"},
                new MimeType {Ext = ".jav", Type = "text/plain"},
                new MimeType {Ext = ".jav", Type = "text/x-java-source"},
                new MimeType {Ext = ".java", Type = "text/plain"},
                new MimeType {Ext = ".java", Type = "text/x-java-source"},
                new MimeType {Ext = ".jcm", Type = "application/x-java-commerce"},
                new MimeType {Ext = ".jfif", Type = "image/jpeg"},
                new MimeType {Ext = ".jfif", Type = "image/pjpeg"},
                new MimeType {Ext = ".jfif-tbnl", Type = "image/jpeg"},
                new MimeType {Ext = ".jpe", Type = "image/jpeg"},
                new MimeType {Ext = ".jpe", Type = "image/pjpeg"},
                new MimeType {Ext = ".jpeg", Type = "image/jpeg"},
                new MimeType {Ext = ".jpeg", Type = "image/pjpeg"},
                new MimeType {Ext = ".jpg", Type = "image/jpeg"},
                new MimeType {Ext = ".jpg", Type = "image/pjpeg"},
                new MimeType {Ext = ".jps", Type = "image/x-jps"},
                new MimeType {Ext = ".js", Type = "application/x-javascript"},
                new MimeType {Ext = ".js", Type = "application/javascript"},
                new MimeType {Ext = ".js", Type = "application/ecmascript"},
                new MimeType {Ext = ".js", Type = "text/javascript"},
                new MimeType {Ext = ".js", Type = "text/ecmascript"},
                new MimeType {Ext = ".jut", Type = "image/jutvision"},
                new MimeType {Ext = ".kar", Type = "audio/midi"},
                new MimeType {Ext = ".kar", Type = "music/x-karaoke"},
                new MimeType {Ext = ".ksh", Type = "application/x-ksh"},
                new MimeType {Ext = ".ksh", Type = "text/x-script.ksh"},
                new MimeType {Ext = ".la", Type = "audio/nspaudio"},
                new MimeType {Ext = ".la", Type = "audio/x-nspaudio"},
                new MimeType {Ext = ".lam", Type = "audio/x-liveaudio"},
                new MimeType {Ext = ".latex", Type = "application/x-latex"},
                new MimeType {Ext = ".lha", Type = "application/lha"},
                new MimeType {Ext = ".lha", Type = "application/octet-stream"},
                new MimeType {Ext = ".lha", Type = "application/x-lha"},
                new MimeType {Ext = ".lhx", Type = "application/octet-stream"},
                new MimeType {Ext = ".list", Type = "text/plain"},
                new MimeType {Ext = ".lma", Type = "audio/nspaudio"},
                new MimeType {Ext = ".lma", Type = "audio/x-nspaudio"},
                new MimeType {Ext = ".log", Type = "text/plain"},
                new MimeType {Ext = ".lsp", Type = "application/x-lisp"},
                new MimeType {Ext = ".lsp", Type = "text/x-script.lisp"},
                new MimeType {Ext = ".lst", Type = "text/plain"},
                new MimeType {Ext = ".lsx", Type = "text/x-la-asf"},
                new MimeType {Ext = ".ltx", Type = "application/x-latex"},
                new MimeType {Ext = ".lzh", Type = "application/octet-stream"},
                new MimeType {Ext = ".lzh", Type = "application/x-lzh"},
                new MimeType {Ext = ".lzx", Type = "application/lzx"},
                new MimeType {Ext = ".lzx", Type = "application/octet-stream"},
                new MimeType {Ext = ".lzx", Type = "application/x-lzx"},
                new MimeType {Ext = ".m", Type = "text/plain"},
                new MimeType {Ext = ".m", Type = "text/x-m"},
                new MimeType {Ext = ".m1v", Type = "video/mpeg"},
                new MimeType {Ext = ".m2a", Type = "audio/mpeg"},
                new MimeType {Ext = ".m2v", Type = "video/mpeg"},
                new MimeType {Ext = ".m3u", Type = "audio/x-mpequrl"},
                new MimeType {Ext = ".man", Type = "application/x-troff-man"},
                new MimeType {Ext = ".map", Type = "application/x-navimap"},
                new MimeType {Ext = ".mar", Type = "text/plain"},
                new MimeType {Ext = ".mbd", Type = "application/mbedlet"},
                new MimeType {Ext = ".mc$", Type = "application/x-magic-cap-package-1.0"},
                new MimeType {Ext = ".mcd", Type = "application/mcad"},
                new MimeType {Ext = ".mcd", Type = "application/x-mathcad"},
                new MimeType {Ext = ".mcf", Type = "image/vasa"},
                new MimeType {Ext = ".mcf", Type = "text/mcf"},
                new MimeType {Ext = ".mcp", Type = "application/netmc"},
                new MimeType {Ext = ".me", Type = "application/x-troff-me"},
                new MimeType {Ext = ".mht", Type = "message/rfc822"},
                new MimeType {Ext = ".mhtml", Type = "message/rfc822"},
                new MimeType {Ext = ".mid", Type = "application/x-midi"},
                new MimeType {Ext = ".mid", Type = "audio/midi"},
                new MimeType {Ext = ".mid", Type = "audio/x-mid"},
                new MimeType {Ext = ".mid", Type = "audio/x-midi"},
                new MimeType {Ext = ".mid", Type = "music/crescendo"},
                new MimeType {Ext = ".mid", Type = "x-music/x-midi"},
                new MimeType {Ext = ".midi", Type = "application/x-midi"},
                new MimeType {Ext = ".midi", Type = "audio/midi"},
                new MimeType {Ext = ".midi", Type = "audio/x-mid"},
                new MimeType {Ext = ".midi", Type = "audio/x-midi"},
                new MimeType {Ext = ".midi", Type = "music/crescendo"},
                new MimeType {Ext = ".midi", Type = "x-music/x-midi"},
                new MimeType {Ext = ".mif", Type = "application/x-frame"},
                new MimeType {Ext = ".mif", Type = "application/x-mif"},
                new MimeType {Ext = ".mime", Type = "message/rfc822"},
                new MimeType {Ext = ".mime", Type = "www/mime"},
                new MimeType {Ext = ".mjf", Type = "audio/x-vnd.audioexplosion.mjuicemediafile"},
                new MimeType {Ext = ".mjpg", Type = "video/x-motion-jpeg"},
                new MimeType {Ext = ".mm", Type = "application/base64"},
                new MimeType {Ext = ".mm", Type = "application/x-meme"},
                new MimeType {Ext = ".mme", Type = "application/base64"},
                new MimeType {Ext = ".mod", Type = "audio/mod"},
                new MimeType {Ext = ".mod", Type = "audio/x-mod"},
                new MimeType {Ext = ".moov", Type = "video/quicktime"},
                new MimeType {Ext = ".mov", Type = "video/quicktime"},
                new MimeType {Ext = ".movie", Type = "video/x-sgi-movie"},
                new MimeType {Ext = ".mp2", Type = "audio/mpeg"},
                new MimeType {Ext = ".mp2", Type = "audio/x-mpeg"},
                new MimeType {Ext = ".mp2", Type = "video/mpeg"},
                new MimeType {Ext = ".mp2", Type = "video/x-mpeg"},
                new MimeType {Ext = ".mp2", Type = "video/x-mpeq2a"},
                new MimeType {Ext = ".mp3", Type = "audio/mpeg3"},
                new MimeType {Ext = ".mp3", Type = "audio/x-mpeg-3"},
                new MimeType {Ext = ".mp3", Type = "video/mpeg"},
                new MimeType {Ext = ".mp3", Type = "video/x-mpeg"},
                new MimeType {Ext = ".mpa", Type = "audio/mpeg"},
                new MimeType {Ext = ".mpa", Type = "video/mpeg"},
                new MimeType {Ext = ".mpc", Type = "application/x-project"},
                new MimeType {Ext = ".mpe", Type = "video/mpeg"},
                new MimeType {Ext = ".mpeg", Type = "video/mpeg"},
                new MimeType {Ext = ".mpg", Type = "audio/mpeg"},
                new MimeType {Ext = ".mpg", Type = "video/mpeg"},
                new MimeType {Ext = ".mpga", Type = "audio/mpeg"},
                new MimeType {Ext = ".mpp", Type = "application/vnd.ms-project"},
                new MimeType {Ext = ".mpt", Type = "application/x-project"},
                new MimeType {Ext = ".mpv", Type = "application/x-project"},
                new MimeType {Ext = ".mpx", Type = "application/x-project"},
                new MimeType {Ext = ".mrc", Type = "application/marc"},
                new MimeType {Ext = ".ms", Type = "application/x-troff-ms"},
                new MimeType {Ext = ".mv", Type = "video/x-sgi-movie"},
                new MimeType {Ext = ".my", Type = "audio/make"},
                new MimeType {Ext = ".mzz", Type = "application/x-vnd.audioexplosion.mzz"},
                new MimeType {Ext = ".nap", Type = "image/naplps"},
                new MimeType {Ext = ".naplps", Type = "image/naplps"},
                new MimeType {Ext = ".nc", Type = "application/x-netcdf"},
                new MimeType {Ext = ".ncm", Type = "application/vnd.nokia.configuration-message"},
                new MimeType {Ext = ".nif", Type = "image/x-niff"},
                new MimeType {Ext = ".niff", Type = "image/x-niff"},
                new MimeType {Ext = ".nix", Type = "application/x-mix-transfer"},
                new MimeType {Ext = ".nsc", Type = "application/x-conference"},
                new MimeType {Ext = ".nvd", Type = "application/x-navidoc"},
                new MimeType {Ext = ".o", Type = "application/octet-stream"},
                new MimeType {Ext = ".oda", Type = "application/oda"},
                new MimeType {Ext = ".omc", Type = "application/x-omc"},
                new MimeType {Ext = ".omcd", Type = "application/x-omcdatamaker"},
                new MimeType {Ext = ".omcr", Type = "application/x-omcregerator"},
                new MimeType {Ext = ".p", Type = "text/x-pascal"},
                new MimeType {Ext = ".p10", Type = "application/pkcs10"},
                new MimeType {Ext = ".p10", Type = "application/x-pkcs10"},
                new MimeType {Ext = ".p12", Type = "application/pkcs-12"},
                new MimeType {Ext = ".p12", Type = "application/x-pkcs12"},
                new MimeType {Ext = ".p7a", Type = "application/x-pkcs7-signature"},
                new MimeType {Ext = ".p7c", Type = "application/pkcs7-mime"},
                new MimeType {Ext = ".p7c", Type = "application/x-pkcs7-mime"},
                new MimeType {Ext = ".p7m", Type = "application/pkcs7-mime"},
                new MimeType {Ext = ".p7m", Type = "application/x-pkcs7-mime"},
                new MimeType {Ext = ".p7r", Type = "application/x-pkcs7-certreqresp"},
                new MimeType {Ext = ".p7s", Type = "application/pkcs7-signature"},
                new MimeType {Ext = ".part", Type = "application/pro_eng"},
                new MimeType {Ext = ".pas", Type = "text/pascal"},
                new MimeType {Ext = ".pbm", Type = "image/x-portable-bitmap"},
                new MimeType {Ext = ".pcl", Type = "application/vnd.hp-pcl"},
                new MimeType {Ext = ".pcl", Type = "application/x-pcl"},
                new MimeType {Ext = ".pct", Type = "image/x-pict"},
                new MimeType {Ext = ".pcx", Type = "image/x-pcx"},
                new MimeType {Ext = ".pdb", Type = "chemical/x-pdb"},
                new MimeType {Ext = ".pdf", Type = "application/pdf"},
                new MimeType {Ext = ".pfunk", Type = "audio/make"},
                new MimeType {Ext = ".pfunk", Type = "audio/make.my.funk"},
                new MimeType {Ext = ".pgm", Type = "image/x-portable-graymap"},
                new MimeType {Ext = ".pgm", Type = "image/x-portable-greymap"},
                new MimeType {Ext = ".pic", Type = "image/pict"},
                new MimeType {Ext = ".pict", Type = "image/pict"},
                new MimeType {Ext = ".pkg", Type = "application/x-newton-compatible-pkg"},
                new MimeType {Ext = ".pko", Type = "application/vnd.ms-pki.pko"},
                new MimeType {Ext = ".pl", Type = "text/plain"},
                new MimeType {Ext = ".pl", Type = "text/x-script.perl"},
                new MimeType {Ext = ".plx", Type = "application/x-pixclscript"},
                new MimeType {Ext = ".pm", Type = "image/x-xpixmap"},
                new MimeType {Ext = ".pm", Type = "text/x-script.perl-module"},
                new MimeType {Ext = ".pm4", Type = "application/x-pagemaker"},
                new MimeType {Ext = ".pm5", Type = "application/x-pagemaker"},
                new MimeType {Ext = ".png", Type = "image/png"},
                new MimeType {Ext = ".pnm", Type = "application/x-portable-anymap"},
                new MimeType {Ext = ".pnm", Type = "image/x-portable-anymap"},
                new MimeType {Ext = ".pot", Type = "application/mspowerpoint"},
                new MimeType {Ext = ".pot", Type = "application/vnd.ms-powerpoint"},
                new MimeType {Ext = ".pov", Type = "model/x-pov"},
                new MimeType {Ext = ".ppa", Type = "application/vnd.ms-powerpoint"},
                new MimeType {Ext = ".ppm", Type = "image/x-portable-pixmap"},
                new MimeType {Ext = ".pps", Type = "application/mspowerpoint"},
                new MimeType {Ext = ".pps", Type = "application/vnd.ms-powerpoint"},
                new MimeType {Ext = ".ppt", Type = "application/mspowerpoint"},
                new MimeType {Ext = ".ppt", Type = "application/powerpoint"},
                new MimeType {Ext = ".ppt", Type = "application/vnd.ms-powerpoint"},
                new MimeType {Ext = ".ppt", Type = "application/x-mspowerpoint"},
                new MimeType {Ext = ".ppz", Type = "application/mspowerpoint"},
                new MimeType {Ext = ".pre", Type = "application/x-freelance"},
                new MimeType {Ext = ".prt", Type = "application/pro_eng"},
                new MimeType {Ext = ".ps", Type = "application/postscript"},
                new MimeType {Ext = ".psd", Type = "application/octet-stream"},
                new MimeType {Ext = ".pvu", Type = "paleovu/x-pv"},
                new MimeType {Ext = ".pwz", Type = "application/vnd.ms-powerpoint"},
                new MimeType {Ext = ".py", Type = "text/x-script.phyton"},
                new MimeType {Ext = ".pyc", Type = "application/x-bytecode.python"},
                new MimeType {Ext = ".qcp", Type = "audio/vnd.qcelp"},
                new MimeType {Ext = ".qd3", Type = "x-world/x-3dmf"},
                new MimeType {Ext = ".qd3d", Type = "x-world/x-3dmf"},
                new MimeType {Ext = ".qif", Type = "image/x-quicktime"},
                new MimeType {Ext = ".qt", Type = "video/quicktime"},
                new MimeType {Ext = ".qtc", Type = "video/x-qtc"},
                new MimeType {Ext = ".qti", Type = "image/x-quicktime"},
                new MimeType {Ext = ".qtif", Type = "image/x-quicktime"},
                new MimeType {Ext = ".ra", Type = "audio/x-pn-realaudio"},
                new MimeType {Ext = ".ra", Type = "audio/x-pn-realaudio-plugin"},
                new MimeType {Ext = ".ra", Type = "audio/x-realaudio"},
                new MimeType {Ext = ".ram", Type = "audio/x-pn-realaudio"},
                new MimeType {Ext = ".ras", Type = "application/x-cmu-raster"},
                new MimeType {Ext = ".ras", Type = "image/cmu-raster"},
                new MimeType {Ext = ".ras", Type = "image/x-cmu-raster"},
                new MimeType {Ext = ".rast", Type = "image/cmu-raster"},
                new MimeType {Ext = ".rexx", Type = "text/x-script.rexx"},
                new MimeType {Ext = ".rf", Type = "image/vnd.rn-realflash"},
                new MimeType {Ext = ".rgb", Type = "image/x-rgb"},
                new MimeType {Ext = ".rm", Type = "application/vnd.rn-realmedia"},
                new MimeType {Ext = ".rm", Type = "audio/x-pn-realaudio"},
                new MimeType {Ext = ".rmi", Type = "audio/mid"},
                new MimeType {Ext = ".rmm", Type = "audio/x-pn-realaudio"},
                new MimeType {Ext = ".rmp", Type = "audio/x-pn-realaudio"},
                new MimeType {Ext = ".rmp", Type = "audio/x-pn-realaudio-plugin"},
                new MimeType {Ext = ".rng", Type = "application/ringing-tones"},
                new MimeType {Ext = ".rng", Type = "application/vnd.nokia.ringing-tone"},
                new MimeType {Ext = ".rnx", Type = "application/vnd.rn-realplayer"},
                new MimeType {Ext = ".roff", Type = "application/x-troff"},
                new MimeType {Ext = ".rp", Type = "image/vnd.rn-realpix"},
                new MimeType {Ext = ".rpm", Type = "audio/x-pn-realaudio-plugin"},
                new MimeType {Ext = ".rt", Type = "text/richtext"},
                new MimeType {Ext = ".rt", Type = "text/vnd.rn-realtext"},
                new MimeType {Ext = ".rtf", Type = "application/rtf"},
                new MimeType {Ext = ".rtf", Type = "application/x-rtf"},
                new MimeType {Ext = ".rtf", Type = "text/richtext"},
                new MimeType {Ext = ".rtx", Type = "application/rtf"},
                new MimeType {Ext = ".rtx", Type = "text/richtext"},
                new MimeType {Ext = ".rv", Type = "video/vnd.rn-realvideo"},
                new MimeType {Ext = ".s", Type = "text/x-asm"},
                new MimeType {Ext = ".s3m", Type = "audio/s3m"},
                new MimeType {Ext = ".saveme", Type = "application/octet-stream"},
                new MimeType {Ext = ".sbk", Type = "application/x-tbook"},
                new MimeType {Ext = ".scm", Type = "application/x-lotusscreencam"},
                new MimeType {Ext = ".scm", Type = "text/x-script.guile"},
                new MimeType {Ext = ".scm", Type = "text/x-script.scheme"},
                new MimeType {Ext = ".scm", Type = "video/x-scm"},
                new MimeType {Ext = ".sdml", Type = "text/plain"},
                new MimeType {Ext = ".sdp", Type = "application/sdp"},
                new MimeType {Ext = ".sdp", Type = "application/x-sdp"},
                new MimeType {Ext = ".sdr", Type = "application/sounder"},
                new MimeType {Ext = ".sea", Type = "application/sea"},
                new MimeType {Ext = ".sea", Type = "application/x-sea"},
                new MimeType {Ext = ".set", Type = "application/set"},
                new MimeType {Ext = ".sgm", Type = "text/sgml"},
                new MimeType {Ext = ".sgm", Type = "text/x-sgml"},
                new MimeType {Ext = ".sgml", Type = "text/sgml"},
                new MimeType {Ext = ".sgml", Type = "text/x-sgml"},
                new MimeType {Ext = ".sh", Type = "application/x-bsh"},
                new MimeType {Ext = ".sh", Type = "application/x-sh"},
                new MimeType {Ext = ".sh", Type = "application/x-shar"},
                new MimeType {Ext = ".sh", Type = "text/x-script.sh"},
                new MimeType {Ext = ".shar", Type = "application/x-bsh"},
                new MimeType {Ext = ".shar", Type = "application/x-shar"},
                new MimeType {Ext = ".shtml", Type = "text/html"},
                new MimeType {Ext = ".shtml", Type = "text/x-server-parsed-html"},
                new MimeType {Ext = ".sid", Type = "audio/x-psid"},
                new MimeType {Ext = ".sit", Type = "application/x-sit"},
                new MimeType {Ext = ".sit", Type = "application/x-stuffit"},
                new MimeType {Ext = ".skd", Type = "application/x-koan"},
                new MimeType {Ext = ".skm", Type = "application/x-koan"},
                new MimeType {Ext = ".skp", Type = "application/x-koan"},
                new MimeType {Ext = ".skt", Type = "application/x-koan"},
                new MimeType {Ext = ".sl", Type = "application/x-seelogo"},
                new MimeType {Ext = ".smi", Type = "application/smil"},
                new MimeType {Ext = ".smil", Type = "application/smil"},
                new MimeType {Ext = ".snd", Type = "audio/basic"},
                new MimeType {Ext = ".snd", Type = "audio/x-adpcm"},
                new MimeType {Ext = ".sol", Type = "application/solids"},
                new MimeType {Ext = ".spc", Type = "application/x-pkcs7-certificates"},
                new MimeType {Ext = ".spc", Type = "text/x-speech"},
                new MimeType {Ext = ".spl", Type = "application/futuresplash"},
                new MimeType {Ext = ".spr", Type = "application/x-sprite"},
                new MimeType {Ext = ".sprite", Type = "application/x-sprite"},
                new MimeType {Ext = ".src", Type = "application/x-wais-source"},
                new MimeType {Ext = ".ssi", Type = "text/x-server-parsed-html"},
                new MimeType {Ext = ".ssm", Type = "application/streamingmedia"},
                new MimeType {Ext = ".sst", Type = "application/vnd.ms-pki.certstore"},
                new MimeType {Ext = ".step", Type = "application/step"},
                new MimeType {Ext = ".stl", Type = "application/sla"},
                new MimeType {Ext = ".stl", Type = "application/vnd.ms-pki.stl"},
                new MimeType {Ext = ".stl", Type = "application/x-navistyle"},
                new MimeType {Ext = ".stp", Type = "application/step"},
                new MimeType {Ext = ".sv4cpio", Type = "application/x-sv4cpio"},
                new MimeType {Ext = ".sv4crc", Type = "application/x-sv4crc"},
                new MimeType {Ext = ".svf", Type = "image/vnd.dwg"},
                new MimeType {Ext = ".svf", Type = "image/x-dwg"},
                new MimeType {Ext = ".svr", Type = "application/x-world"},
                new MimeType {Ext = ".svr", Type = "x-world/x-svr"},
                new MimeType {Ext = ".swf", Type = "application/x-shockwave-flash"},
                new MimeType {Ext = ".t", Type = "application/x-troff"},
                new MimeType {Ext = ".talk", Type = "text/x-speech"},
                new MimeType {Ext = ".tar", Type = "application/x-tar"},
                new MimeType {Ext = ".tbk", Type = "application/toolbook"},
                new MimeType {Ext = ".tbk", Type = "application/x-tbook"},
                new MimeType {Ext = ".tcl", Type = "application/x-tcl"},
                new MimeType {Ext = ".tcl", Type = "text/x-script.tcl"},
                new MimeType {Ext = ".tcsh", Type = "text/x-script.tcsh"},
                new MimeType {Ext = ".tex", Type = "application/x-tex"},
                new MimeType {Ext = ".texi", Type = "application/x-texinfo"},
                new MimeType {Ext = ".texinfo", Type = "application/x-texinfo"},
                new MimeType {Ext = ".text", Type = "application/plain"},
                new MimeType {Ext = ".text", Type = "text/plain"},
                new MimeType {Ext = ".tgz", Type = "application/gnutar"},
                new MimeType {Ext = ".tgz", Type = "application/x-compressed"},
                new MimeType {Ext = ".tif", Type = "image/tiff"},
                new MimeType {Ext = ".tif", Type = "image/x-tiff"},
                new MimeType {Ext = ".tiff", Type = "image/tiff"},
                new MimeType {Ext = ".tiff", Type = "image/x-tiff"},
                new MimeType {Ext = ".tr", Type = "application/x-troff"},
                new MimeType {Ext = ".tsi", Type = "audio/tsp-audio"},
                new MimeType {Ext = ".tsp", Type = "application/dsptype"},
                new MimeType {Ext = ".tsp", Type = "audio/tsplayer"},
                new MimeType {Ext = ".tsv", Type = "text/tab-separated-values"},
                new MimeType {Ext = ".turbot", Type = "image/florian"},
                new MimeType {Ext = ".txt", Type = "text/plain"},
                new MimeType {Ext = ".uil", Type = "text/x-uil"},
                new MimeType {Ext = ".uni", Type = "text/uri-list"},
                new MimeType {Ext = ".unis", Type = "text/uri-list"},
                new MimeType {Ext = ".unv", Type = "application/i-deas"},
                new MimeType {Ext = ".uri", Type = "text/uri-list"},
                new MimeType {Ext = ".uris", Type = "text/uri-list"},
                new MimeType {Ext = ".ustar", Type = "application/x-ustar"},
                new MimeType {Ext = ".ustar", Type = "multipart/x-ustar"},
                new MimeType {Ext = ".uu", Type = "application/octet-stream"},
                new MimeType {Ext = ".uu", Type = "text/x-uuencode"},
                new MimeType {Ext = ".uue", Type = "text/x-uuencode"},
                new MimeType {Ext = ".vcd", Type = "application/x-cdlink"},
                new MimeType {Ext = ".vcs", Type = "text/x-vcalendar"},
                new MimeType {Ext = ".vda", Type = "application/vda"},
                new MimeType {Ext = ".vdo", Type = "video/vdo"},
                new MimeType {Ext = ".vew", Type = "application/groupwise"},
                new MimeType {Ext = ".viv", Type = "video/vivo"},
                new MimeType {Ext = ".viv", Type = "video/vnd.vivo"},
                new MimeType {Ext = ".vivo", Type = "video/vivo"},
                new MimeType {Ext = ".vivo", Type = "video/vnd.vivo"},
                new MimeType {Ext = ".vmd", Type = "application/vocaltec-media-desc"},
                new MimeType {Ext = ".vmf", Type = "application/vocaltec-media-file"},
                new MimeType {Ext = ".voc", Type = "audio/voc"},
                new MimeType {Ext = ".voc", Type = "audio/x-voc"},
                new MimeType {Ext = ".vos", Type = "video/vosaic"},
                new MimeType {Ext = ".vox", Type = "audio/voxware"},
                new MimeType {Ext = ".vqe", Type = "audio/x-twinvq-plugin"},
                new MimeType {Ext = ".vqf", Type = "audio/x-twinvq"},
                new MimeType {Ext = ".vql", Type = "audio/x-twinvq-plugin"},
                new MimeType {Ext = ".vrml", Type = "application/x-vrml"},
                new MimeType {Ext = ".vrml", Type = "model/vrml"},
                new MimeType {Ext = ".vrml", Type = "x-world/x-vrml"},
                new MimeType {Ext = ".vrt", Type = "x-world/x-vrt"},
                new MimeType {Ext = ".vsd", Type = "application/x-visio"},
                new MimeType {Ext = ".vst", Type = "application/x-visio"},
                new MimeType {Ext = ".vsw", Type = "application/x-visio"},
                new MimeType {Ext = ".w60", Type = "application/wordperfect6.0"},
                new MimeType {Ext = ".w61", Type = "application/wordperfect6.1"},
                new MimeType {Ext = ".w6w", Type = "application/msword"},
                new MimeType {Ext = ".wav", Type = "audio/wav"},
                new MimeType {Ext = ".wav", Type = "audio/x-wav"},
                new MimeType {Ext = ".wb1", Type = "application/x-qpro"},
                new MimeType {Ext = ".wbmp", Type = "image/vnd.wap.wbmp"},
                new MimeType {Ext = ".web", Type = "application/vnd.xara"},
                new MimeType {Ext = ".wiz", Type = "application/msword"},
                new MimeType {Ext = ".wk1", Type = "application/x-123"},
                new MimeType {Ext = ".wmf", Type = "windows/metafile"},
                new MimeType {Ext = ".wml", Type = "text/vnd.wap.wml"},
                new MimeType {Ext = ".wmlc", Type = "application/vnd.wap.wmlc"},
                new MimeType {Ext = ".wmls", Type = "text/vnd.wap.wmlscript"},
                new MimeType {Ext = ".wmlsc", Type = "application/vnd.wap.wmlscriptc"},
                new MimeType {Ext = ".word", Type = "application/msword"},
                new MimeType {Ext = ".wp", Type = "application/wordperfect"},
                new MimeType {Ext = ".wp5", Type = "application/wordperfect"},
                new MimeType {Ext = ".wp5", Type = "application/wordperfect6.0"},
                new MimeType {Ext = ".wp6", Type = "application/wordperfect"},
                new MimeType {Ext = ".wpd", Type = "application/wordperfect"},
                new MimeType {Ext = ".wpd", Type = "application/x-wpwin"},
                new MimeType {Ext = ".wq1", Type = "application/x-lotus"},
                new MimeType {Ext = ".wri", Type = "application/mswrite"},
                new MimeType {Ext = ".wri", Type = "application/x-wri"},
                new MimeType {Ext = ".wrl", Type = "application/x-world"},
                new MimeType {Ext = ".wrl", Type = "model/vrml"},
                new MimeType {Ext = ".wrl", Type = "x-world/x-vrml"},
                new MimeType {Ext = ".wrz", Type = "model/vrml"},
                new MimeType {Ext = ".wrz", Type = "x-world/x-vrml"},
                new MimeType {Ext = ".wsc", Type = "text/scriplet"},
                new MimeType {Ext = ".wsrc", Type = "application/x-wais-source"},
                new MimeType {Ext = ".wtk", Type = "application/x-wintalk"},
                new MimeType {Ext = ".xbm", Type = "image/x-xbitmap"},
                new MimeType {Ext = ".xbm", Type = "image/x-xbm"},
                new MimeType {Ext = ".xbm", Type = "image/xbm"},
                new MimeType {Ext = ".xdr", Type = "video/x-amt-demorun"},
                new MimeType {Ext = ".xgz", Type = "xgl/drawing"},
                new MimeType {Ext = ".xif", Type = "image/vnd.xiff"},
                new MimeType {Ext = ".xl", Type = "application/excel"},
                new MimeType {Ext = ".xla", Type = "application/excel"},
                new MimeType {Ext = ".xla", Type = "application/x-excel"},
                new MimeType {Ext = ".xla", Type = "application/x-msexcel"},
                new MimeType {Ext = ".xlb", Type = "application/excel"},
                new MimeType {Ext = ".xlb", Type = "application/vnd.ms-excel"},
                new MimeType {Ext = ".xlb", Type = "application/x-excel"},
                new MimeType {Ext = ".xlc", Type = "application/excel"},
                new MimeType {Ext = ".xlc", Type = "application/vnd.ms-excel"},
                new MimeType {Ext = ".xlc", Type = "application/x-excel"},
                new MimeType {Ext = ".xld", Type = "application/excel"},
                new MimeType {Ext = ".xld", Type = "application/x-excel"},
                new MimeType {Ext = ".xlk", Type = "application/excel"},
                new MimeType {Ext = ".xlk", Type = "application/x-excel"},
                new MimeType {Ext = ".xll", Type = "application/excel"},
                new MimeType {Ext = ".xll", Type = "application/vnd.ms-excel"},
                new MimeType {Ext = ".xll", Type = "application/x-excel"},
                new MimeType {Ext = ".xlm", Type = "application/excel"},
                new MimeType {Ext = ".xlm", Type = "application/vnd.ms-excel"},
                new MimeType {Ext = ".xlm", Type = "application/x-excel"},
                new MimeType {Ext = ".xls", Type = "application/excel"},
                new MimeType {Ext = ".xlsx", Type = "application/x-msexcel"},
                new MimeType {Ext = ".xlt", Type = "application/excel"},
                new MimeType {Ext = ".xlt", Type = "application/x-excel"},
                new MimeType {Ext = ".xlv", Type = "application/excel"},
                new MimeType {Ext = ".xlv", Type = "application/x-excel"},
                new MimeType {Ext = ".xlw", Type = "application/excel"},
                new MimeType {Ext = ".xlw", Type = "application/vnd.ms-excel"},
                new MimeType {Ext = ".xlw", Type = "application/x-excel"},
                new MimeType {Ext = ".xlw", Type = "application/x-msexcel"},
                new MimeType {Ext = ".xm", Type = "audio/xm"},
                new MimeType {Ext = ".xml", Type = "application/xml"},
                new MimeType {Ext = ".xml", Type = "text/xml"},
                new MimeType {Ext = ".xmz", Type = "xgl/movie"},
                new MimeType {Ext = ".xpix", Type = "application/x-vnd.ls-xpix"},
                new MimeType {Ext = ".xpm", Type = "image/x-xpixmap"},
                new MimeType {Ext = ".xpm", Type = "image/xpm"},
                new MimeType {Ext = ".x-png", Type = "image/png"},
                new MimeType {Ext = ".xsr", Type = "video/x-amt-showrun"},
                new MimeType {Ext = ".xwd", Type = "image/x-xwd"},
                new MimeType {Ext = ".xwd", Type = "image/x-xwindowdump"},
                new MimeType {Ext = ".xyz", Type = "chemical/x-pdb"},
                new MimeType {Ext = ".z", Type = "application/x-compress"},
                new MimeType {Ext = ".z", Type = "application/x-compressed"},
                new MimeType {Ext = ".zip", Type = "application/x-compressed"},
                new MimeType {Ext = ".zip", Type = "application/x-zip-compressed"},
                new MimeType {Ext = ".zip", Type = "application/zip"},
                new MimeType {Ext = ".zip", Type = "multipart/x-zip"},
                new MimeType {Ext = ".zoo", Type = "application/octet-stream"},
                new MimeType {Ext = ".zsh", Type = "text/x-script.zsh"},
                new MimeType {Ext = ".rar", Type = "application/x-compressed"},
            };

            var index = 0;
            list.ForEach(item =>
            {
                if (!mimeTypes.Any(x => x.Ext == item.Ext))
                {
                    item.Index = index;
                    index++;
                    mimeTypes.Add(item);
                }
            });
            return mimeTypes;
        }

        public static int AddMime(string ext)
        {
            var mime = new MimeType
            {
                Ext = ext
            };
            return AddMime(mime);
        }

        public static int AddMime(MimeType mime)
        {
            lock (Lock)
            {
                var type = mimeTypes.FirstOrDefault(item => item.Ext == mime.Ext);
                if (type != null) return type.Index;
                using (var fs = new FileStream(MimeTypeFilePath, FileMode.OpenOrCreate))
                {
                    var sw = new StreamWriter(fs);
                    sw.WriteLine($"{mime.Ext} {mime.Type}");
                    mimeTypes.Add(mime);
                    mime.Index = mimeTypes.Count() - 1;
                    sw.Close();
                }

                return mime.Index;
            }
        }

        public static void AddMime(IEnumerable<MimeType> mimeTypes)
        {
            lock (Lock)
            {
                using (var fs = new FileStream(MimeTypeFilePath, FileMode.OpenOrCreate))
                {
                    var sw = new StreamWriter(fs);
                    foreach (var mime in mimeTypes)
                    {
                        if (MimeType.mimeTypes.Any(item => item.Ext == mime.Ext)) continue;
                        sw.WriteLine($"{mime.Ext} {mime.Type}");
                        MimeType.mimeTypes.Add(mime);
                        mime.Index = MimeType.mimeTypes.Count() - 1;
                    }
                    sw.Close();
                }
            }
        }

        public static IEnumerable<MimeType> ReadMimeFromFile()
        {
            if (!File.Exists(MimeTypeFilePath))
            {
                return InitData();
            }
            if (!isFirstRead) return mimeTypes;

            isFirstRead = false;
            var result = new List<MimeType>();
            using (var fs = new FileStream(MimeTypeFilePath, FileMode.Open))
            {
                var sr = new StreamReader(fs);
                var index = 0;
                while (true)
                {
                    var line = sr.ReadLine();
                    if (line == null)
                        break;
                    var array = line.Trim().Split(' ');
                    if (array.Any() && array.Length >= 1)
                    {
                        var mime = new MimeType
                        {
                            Index = index,
                            Ext = array[0].Trim()
                        };
                        if (array.Length >= 2)
                        {
                            mime.Type = array[1].Trim();
                        }
                        result.Add(mime);
                    }
                    index++;
                }
                sr.Close();
            }
            return result;
        }
        #endregion
    }

}
